package com.example.flower_shop.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "统一响应结果")
public class Result implements Serializable {
    @Schema(description = "状态码", example = "200")
    private int code;
    @Schema(description = "消息", example = "success")
    private String msg;
    @Schema(description = "数据")
    private Object data;

    public static Result success(Object data) {
        return new Result(200, "success", data);
    }

    public static Result fail(String msg) {
        return new Result(500, msg, null);
    }

    public static Result fail(int code, String msg) {
        return new Result(code, msg, null);
    }
}
